package org.jeecg.modules.demo.mpwlwjc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.mpwlwjc.entity.ZwglImageManagement;
import org.jeecg.modules.demo.mpwlwjc.entity.ZwglMpsbsj;
import org.jeecg.modules.demo.mpwlwjc.service.IZwglMpsbsjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 苗棚设备数据
 * @Author: jeecg-boot
 * @Date: 2023-04-17
 * @Version: V1.0
 */
@Api(tags = "苗棚设备数据")
@RestController
@RequestMapping("/mpwlwjc/zwglMpsbsj")
@Slf4j
@EnableScheduling
public class ZwglMpsbsjController extends JeecgController<ZwglMpsbsj, IZwglMpsbsjService> {
    @Autowired
    private IZwglMpsbsjService zwglMpsbsjService;

    /**
     * 分页列表查询
     *
     * @param zwglMpsbsj
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "苗棚设备数据-分页列表查询")
    @ApiOperation(value = "苗棚设备数据-分页列表查询", notes = "苗棚设备数据-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ZwglMpsbsj>> queryPageList(ZwglMpsbsj zwglMpsbsj,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest req) {
        QueryWrapper<ZwglMpsbsj> queryWrapper = QueryGenerator.initQueryWrapper(zwglMpsbsj, req.getParameterMap());
        Page<ZwglMpsbsj> page = new Page<ZwglMpsbsj>(pageNo, pageSize);
        IPage<ZwglMpsbsj> pageList = zwglMpsbsjService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param zwglMpsbsj
     * @return
     */
    @AutoLog(value = "苗棚设备数据-添加")
    @ApiOperation(value = "苗棚设备数据-添加", notes = "苗棚设备数据-添加")
//	@RequiresPermissions("mpwlwjc:zwgl_mpsbsj:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ZwglMpsbsj zwglMpsbsj) {
        zwglMpsbsjService.save(zwglMpsbsj);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param zwglMpsbsj
     * @return
     */
    @AutoLog(value = "苗棚设备数据-编辑")
    @ApiOperation(value = "苗棚设备数据-编辑", notes = "苗棚设备数据-编辑")
//	@RequiresPermissions("mpwlwjc:zwgl_mpsbsj:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ZwglMpsbsj zwglMpsbsj) {
        zwglMpsbsjService.updateById(zwglMpsbsj);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "苗棚设备数据-通过id删除")
    @ApiOperation(value = "苗棚设备数据-通过id删除", notes = "苗棚设备数据-通过id删除")
//	@RequiresPermissions("mpwlwjc:zwgl_mpsbsj:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        zwglMpsbsjService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "苗棚设备数据-批量删除")
    @ApiOperation(value = "苗棚设备数据-批量删除", notes = "苗棚设备数据-批量删除")
//	@RequiresPermissions("mpwlwjc:zwgl_mpsbsj:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.zwglMpsbsjService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "苗棚设备数据-通过id查询")
    @ApiOperation(value = "苗棚设备数据-通过id查询", notes = "苗棚设备数据-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ZwglMpsbsj> queryById(@RequestParam(name = "id", required = true) String id) {
        ZwglMpsbsj zwglMpsbsj = zwglMpsbsjService.getById(id);
        if (zwglMpsbsj == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(zwglMpsbsj);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param zwglMpsbsj
     */
//    @RequiresPermissions("mpwlwjc:zwgl_mpsbsj:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZwglMpsbsj zwglMpsbsj) {
        return super.exportXls(request, zwglMpsbsj, ZwglMpsbsj.class, "苗棚设备数据");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
//    @RequiresPermissions("mpwlwjc:zwgl_mpsbsj:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZwglMpsbsj.class);
    }

    @GetMapping(value = "/getmpsj")
    @Scheduled(fixedRate = 1800000)
    public Result getmpsj() {
        QueryWrapper<ZwglImageManagement> queryWrapper = new QueryWrapper<>();
        String s = zwglMpsbsjService.getMpsj();

        return Result.OK(s);
    }

    @GetMapping(value = "/getzuigao")
    @Scheduled(fixedRate = 3600000)
    public String getzuigao() {
//		 zwglMpsbsjService.zuigao();
        return zwglMpsbsjService.zuigao();
    }

    @GetMapping(value = "/getpjguangzhao")
    @Scheduled(fixedRate = 3600000)
    public String getpjguangzhao() {
//		 zwglMpsbsjService.zuigao();
        return zwglMpsbsjService.pjguangzhao();
    }

    @GetMapping(value = "/getmplssj")
    public Result getmplssj(@RequestParam(name = "sbmc", required = false) String sbmc) {
        return zwglMpsbsjService.getmpmcsj(sbmc);
    }

    @GetMapping(value = "/getmiaopengsj")
    public Result getmiaopengsj(@RequestParam(name = "kaishishijian", required = false) String kaishishijian, @RequestParam(name = "jieshushijian", required = false) String jieshushijian, @RequestParam(name = "sbmc", required = false) String sbmc) {

        return zwglMpsbsjService.getdapengshijian(kaishishijian, jieshushijian, sbmc);
    }

    @GetMapping(value = "/miaopeng")
    public Result miaopeng(@RequestParam(name = "starttime", required = false) String starttime,
                           @RequestParam(name = "endtime", required = false) String endtime,
                           @RequestParam(name = "sbmc", required = false) String sbmc,
                           @RequestParam(name = "page", required = false) Integer pageNo
    ) {
        return zwglMpsbsjService.miaopengshijian(starttime, endtime, sbmc, pageNo);
    }


}
